package com.shs.riggy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shs.riggy.entity.User;
import com.shs.riggy.mapper.UserMapper;
import com.shs.riggy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

/**
 * @Author 晚点再动心
 * @Date 2022/9/20
 */
@Service
@Repository
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

        @Value("${spring.mail.username}")
        private String from;   // 邮件发送人

        @Autowired
        private JavaMailSender mailSender;


        @Override
        public void sendMsg(String to,String subject,String context){
            SimpleMailMessage mailMessage = new SimpleMailMessage();

            mailMessage.setFrom(from);
            mailMessage.setTo(to);
            mailMessage.setSubject(subject);
            mailMessage.setText(context);

            // 真正的发送邮件操作，从 from到 to
            mailSender.send(mailMessage);

        }

    }

